﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.ComponentModel;

using TempEmployees.BLL;
using TempEmployees.BLL.Validations;

namespace TempEmployees.Web
{
    public partial class DisplayTextBoxEmail : BaseDisplayTextBox
    {
        public EventHandler OnTextChanged
        {
            set { DispTextBox.TextChanged += new EventHandler(value); }
        }

        public override bool ReadOnly
        {
            set
            {
                DispLabel.Visible = value;
                DispTextBox.Visible = !value;
                if (value)
                {
                    DispLabel.Text = DispTextBox.Text;
                    DispLabel.NavigateUrl = string.Format("mailto:{0}", DispTextBox.Text);
                }
            }
            get
            {
                return DispLabel.Visible;
            }
        }

        [CategoryAttribute("Appearance")]
        public override string Text
        {
            set
            {
                DispTextBox.Text = value;
                DispLabel.Text = string.Format("mailto:{0}", value);
            }
            get
            {
                return DispTextBox.Text;
            }
        }

        protected override WebControl EditableControl
        {
            get { return DispTextBox; }
        }

        public override void Reset()
        {
            DispTextBox.Text = string.Empty;
            DispLabel.Text = string.Empty;
            DispLabel.NavigateUrl = string.Empty;
        }

        public override bool IsFilled()
        {
            return (DispTextBox.Text.Length > 0);
        }

        public override bool IsValid()
        {
            return ValidationMethodFactory.GetValidationMethod(ValidationType)(DispTextBox.Text);
        }
    }
}